#include "redcar_usb_command.h"
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdarg.h>


USB_CMD Get_USB_data(char *str)
{
	 const char s[2] = ",";
   char *token;
	 float f_num[3];
   int lengthOfstr=0;
	 USB_CMD cmd;
	 token = strtok(str, s);

   /* walk through other tokens */
   while( token != NULL )
	 {

	   f_num[lengthOfstr]=atof(token);
		 lengthOfstr++;
		 token = strtok(NULL, s);
   }
	 if(lengthOfstr==3)
	 {
		 cmd.xf=f_num[0];
		 cmd.yf=f_num[1];
		 cmd.zf=f_num[2];
		 cmd.zf=fabs(cmd.zf);
		 cmd.atan_num=atan(cmd.xf/cmd.zf);
		 cmd.error_code=0;
	 }
	 else
	 {
		 cmd.error_code=1;
		 
	 }
	 return cmd;
   

}

static char usb_tx_buffer[128];
int my_printf(const char* format,...)
{
    int i=-1;

    uint8_t result;


    va_list arg;
    va_start(arg,format);
    i=vsprintf((char *)&usb_tx_buffer,format,arg);


    if(i>0)
    {
        result=CDC_Transmit_FS((uint8_t *)&usb_tx_buffer,i);
        //result=CDC_Transmit_FS((uint8_t* )buffer,i);

    }
    va_end(arg);

    return result;
}
